package com.jackstraw.jack_base.remote_command.service.impl;

import com.jackstraw.jack_base.remote_command.config.JschConfig;
import com.jackstraw.jack_base.remote_command.entity.InstallProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component("kafka" + AbstractGroupControlServiceImpl.BEAN_NAME)
public class KafkaGroupControlServiceImpl extends DockerGroupControlServiceImpl {

    public KafkaGroupControlServiceImpl(JschConfig jschConfig) {
        super(jschConfig);
    }


    @Override
    public void installSingle(InstallProperties installProperties) throws Exception {

        this.startZookeeper(installProperties);

        super.installSingle(installProperties);
    }

    /**
     * 启动zookeeper
     *
     * @param installProperties
     * @throws Exception
     */
    public void startZookeeper(InstallProperties installProperties) throws Exception {
        log.info("即将获取锁的ConnName为：{}", installProperties.getConnName());
        if (this.getLock().tryLock()) {
            try {
                log.info("当前获取锁的ConnName为：{}", installProperties.getConnName());
                List<String> zookeeper = this.jackStart("zookeeper", installProperties.getModelEnum().getCode());
                log.info("zookeeper启动日志为：{}", zookeeper);
            } finally {
                this.getLock().unlock();
            }
        }
    }
}